package com.neusoft.sevice.serviceimpl;

import com.neusoft.feign.OrdersFeignClient;
import com.neusoft.mapper.DeliverymanMapper;
import com.neusoft.po.CommonResult;
import com.neusoft.po.Orders;
import com.neusoft.sevice.DeliverymanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class DeliverymanServiceimpl implements DeliverymanService {

    @Autowired
    private DeliverymanMapper deliverymanMapper;
    @Autowired
    private OrdersFeignClient ordersFeignClient;

    @Override
    public List<Orders> listNonAcceptedOrders(){
        List<Integer> orderIdlist=deliverymanMapper.listNonAcceptedOrders();
        List<Orders> ordersList=new ArrayList<Orders>();
        for(int orderId:orderIdlist){
            CommonResult<Orders> order=ordersFeignClient.getOrderById(orderId);
            if(order.getCode()==200) ordersList.add(order.getResult());
        }
        return ordersList;
    }
    @Override
    public List<Orders> listAcceptedOrderByDeliverymanId(String userid){
        System.out.println(userid);
        List<Integer> orderIdlist=deliverymanMapper.listAcceptedOrderByDeliverymanId(userid);
        List<Orders> ordersList=new ArrayList<Orders>();
        for(int orderId:orderIdlist){
            CommonResult<Orders> order=ordersFeignClient.getOrderById(orderId);
            if(order.getCode()==200) ordersList.add(order.getResult());
        }
        return ordersList;
    }
    @Override
    public int AcceptedOrders(Integer OrderNumber, String userId){
        return deliverymanMapper.AcceptedOrders(OrderNumber, userId);
    }
    @Override
    public int FinishedOrders(Integer OrderNumber){
        return deliverymanMapper.FinishedOrders(OrderNumber);
    }
}
